<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>委外分案</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<script type="text/javascript">
    var grid = null;
    var applyId = null;
    $(function () {
        initOrgTree();
        initGrid();//grid
        $("#searchBar").ligerForm();
        $("#searchBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

    });

    function clearBtn() {
        $("#searchBar").ligerForm();
        var orgId = liger.get("orgId");
        orgId.selectValue(" ");
        var form = new liger.get("searchBar");
        form.setData({
            paySchNo : " ",
            cstNm: " ",
            orgId:"0000",
            minOverdueDay :"",
            maxOverdueDay:" "
        });
    }

    //初始化列表
    function initGrid() {
        var params = {};
        $("#grid").ligerGrid({
            url: '<%=path%>/clt/auth/rskCltAuth/initList.do',
            method: 'get',
            parms: params,
            columns: [
                {display: '事业部', name: 'buOrgNm', minWidth: 60, align: 'center', enabledSort: true},
                {display: '省公司', name: 'cstMgrOrgCdNm', minWidth: 100, align: 'center', enabledSort: true},
                {display: '承租人', name: 'cstNm', minWidth: 80, align: 'center', enabledSort: true,
                    render: function (rowdata, rowindex, value, column) {
                        if(StringUtils.isEmpty(value)){
                            value = "";
                        }
                        var h = '';
                        h='<a href="javascript:showDetail(';
                        h+="'"+rowdata.cstId+"'";
                        h+=",'"+rowdata.cstTypCd+"'";
                        h+=')">'+value+'</a>'
                        return h;
                    }
                },
                {display: '支付表号', name: 'paySchNo', width: 200, align: 'center', enabledSort: true,
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        h += '<a href="javascript:detailBtn(';
                        h += "'" + rowdata.prjPrdDtlId + "',";
                        h += "'" + rowdata.paySchId + "',";
                        h += "'" + rowdata.prjPrdId + "',";
                        h += "'" + rowdata.prjId + "'";
                        h += ')">' + value + '</a>'
                        return h;
                    }},
                {
                    display: '支付表状态', name: 'prdStsCd', minWidth: 80, align: 'center', enabledSort: true,
                    render: function (rowdata, rowindex, value) {
                        var prdStsCd = rowdata.prdStsCd == null ? " " : rowdata.prdStsCd;
                        if (prdStsCd == 'S01') {
                            return "正常";
                        }else if(prdStsCd == 'S010601'){
                            return "无法拖回";
                        }else if(prdStsCd == 'S0101'){
                            return "正常出险";
                        }else if(prdStsCd == 'S0107'){
                            return "添加风险保证金中";
                        }

                    }
                },
                {display: '逾期天数', name: 'overdueDay', minWidth: 80, align: 'center', enabledSort: true},
                {display: '应收金额', name: 'arAmt', minWidth: 80, align: 'center', enabledSort: true,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.arAmt/100);
                    }
                },
                {display: '剩余租金', name: 'residualRent', minWidth: 80, align: 'center', enabledSort: true,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.residualRent/100);
                    }
                },
                {display: '违约金', name: 'breachAmt', minWidth: 80, align: 'center', enabledSort: true,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.breachAmt/100);
                    }
                },
                {display: '委案金额', name: 'authAmt', minWidth: 80, align: 'center', enabledSort: true,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.authAmt/100);
                    }
                },

                {
                    display: '逾期账龄', name: 'overdueDay', minWidth: 80, align: 'center', enabledSort: true,
                    render: function (rowdata, rowindex, value) {
                        var overdueDay = rowdata.overdueDay == null ? " " : rowdata.overdueDay;
                        if (overdueDay <= 90) {
                            return "(0,90]";
                        }else if(overdueDay > 90 && overdueDay <= 180){
                            return "(90,180]";
                        }else if(overdueDay > 180 && overdueDay <= 365){
                            return "(180,365]";
                        }else if(overdueDay > 365 && overdueDay <= 730){
                            return "(365,730]";
                        }else if(overdueDay > 730){
                            return "(730,+]";
                        }

                    }
                },
                {display: '订单开始时间', name: 'startDate', minWidth: 80, align: 'center', enabledSort: true,render: renderDate},
                {display: '订单结束时间', name: 'endDate', minWidth: 80, align: 'center', enabledSort: true,render: renderDate},
                {display: '诉讼状态', name: 'sueStsCdNm', minWidth: 80, align: 'center', enabledSort: true},
                {display: '委案次数', name: 'authCnt', minWidth: 80, align: 'center', enabledSort: true},

                {
                    display: '操作', name: 'flowId', minWidth: 150, align: 'center',
                    render: function (rowdata, rowindex, value, column) {
                        var paySchId = rowdata.paySchId == null ? " " : rowdata.paySchId;
                        var h = '';
                        if (paySchId == " ") {
                            h += "";
                        } else {
                            h += '<a href="javascript:showRskCltAuth(';
                            h += "'" + rowdata.paySchId + "',";
                            h += "'" + rowdata.cstId + "'";
                            h += ')">委案</a>';
                            h += ' | ';
                            h += '<a href="javascript:showFileDetail(';
                            h += "'" + rowdata.prjId + "'";
                            h += ')">资料维护</a>'
                        }
                        return h;
                    }, enabledSort: true
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            allowUnSelectRow: true,
            alternatingRow: true,
            rownumbers: true,
            enabledEdit: true,
            usePagerOnLessPagesize: true,
        });
        grid = liger.get("grid");
        grid.setHeight(500);

    }

    //格式化为人民币格式
    function renderAmt(rowdata, rowindex, value) {
        var h = "￥" + FormatMoney(value);
        return h;
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value && value != '') {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    /* 委案弹框 */
    function showRskCltAuth(paySchId, cstId) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 850,
            height: 500,
            title: '委外催收分案',
            url: '<%=path%>/clt/auth/rskCltAuth/toRskCltAuthPage.do?cstId=' + cstId + "&paySchId=" + paySchId,
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }


    //查看数据
    function showDetail(_id,_cstTypCd){
        //1 自然人  2 法人
        if(_cstTypCd == 1){
            parent.mainApp.f_addTab('tab_customer_np_detail'+_id,'客户详情','<%=path%>/customer/cstbscinfo/toCustCstBacInfoNpDetailPage.do?id='+_id);
        }else if(_cstTypCd == 2){
            parent.mainApp.f_addTab('tab_customer_corp_detail'+_id,'客户详情','<%=path%>/customer/cstbscinfo/toCustCstBacInfoCorpDetailPage.do?id='+_id);
        }
    }

    function initOrgTree(){
        var params = {};
        searchOrgTree = $("#orgId").ligerComboBox({
            width: 480,
            selectBoxWidth: 480,
            selectBoxHeight: 150,
            //限制只能选叶节点，父节点不能点击
            treeLeafOnly: false,
            valueField: 'orgCd',
            textField: 'orgDispNm',
            showTreePath: true,
            tree: {
                ajaxType: 'get',
                idFieldName:'orgCd',
                textFieldName: 'orgDispNm',
                checkbox: false,
                parentIcon: "none",
                childIcon: "none",
                needCancel : false,
                isExpand: 2
            }
        });
        $.ajax({
            type: 'get',
            dataType:'json',
            data: params,
            url: '<%=path%>/project/prjbscinfo/searchBuOrgTree.do',
            success:function(msg){
                if(msg.success == 1){
                    searchOrgTree.treeManager.setData(msg.data);
                    searchOrgTree.clear();
                    searchOrgTree.setValue('0000');
                }else{
                    $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });

    }

    function detailBtn(prjPrdDtlId,id, prjPrdId, prjId) {
        var editFlag = true;
        Add_navTab('tab_prj_quat_prps' + id, '查看支付表','<%=path%>/project/prjprdpayschm/toAddPage.do?prjId=' + prjId + '&id=' + id + '&prjPrdDtlId=' + prjPrdDtlId + '&prjPrdId=' + prjPrdId + '&detailFlag=' + editFlag);
    }

    /**
     * 维护资料
     */
    function showFileDetail(prjId) {
        var onOk = function (item, Dialog) {
            if (Dialog.onOk) Dialog.onOk();
        };
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.open({
            width: 850,
            height: 300,
            title: '资料维护',
            url: '<%=path%>/clt/auth/file/toCltFileListPage.do?edit=1&pkId=' + prjId,
            buttons: [{
                text: "保存", type: 'ok', onclick: onOk
            }, {
                text: "关闭", type: 'cancel', onclick: onCancel, cls: 'l-dialog-btn-no'
            }]
        });
    }

</script>

<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <div class="searchArea">
            <form id="searchBar">
                <div class="fieldset1 clearFix">
                    <div class="fieldBox col_33" id="searchCstNm">
                        <div class="label">支付表号</div>
                        <div class="field">
                            <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                        </div>
                    </div>
                    <div class="fieldBox col_33" id="searchCstNmId">
                        <div class="label">承租人</div>
                        <div class="field">
                            <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                        </div>
                    </div>
                    <div class="fieldBox" id="">
                        <div class="label">所属组织架构</div>
                        <div class="field">
                            <input name="orgId" id="orgId" type="text" class="ui-textbox" value="">
                        </div>
                    </div>
                    <div class="fieldBox">
                        <div class="label">逾期天数</div>
                        <div class="field">
                            <input ligerui="width: 82" name="minOverdueDay" id="minOverdueDay" type="text" class="ui-textbox"
                                   value="" validate="{number:true}">
                            -
                            <input ligerui="width: 82" name="maxOverdueDay" id="maxOverdueDay" type="text" class="ui-textbox"
                                   value="" validate="{number:true}">
                        </div>
                    </div>
                    <div class="clearFix"></div>
                    <div class="btnsBox">
                        <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                        <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
                    </div>
                </div>
            </form>
        </div>
        <div id="grid" class="sq-grid"></div>
    </div>
</div>
</body>
</html>